package com.agriculture.service.impl;

import com.agriculture.common.Response;
import com.agriculture.domain.Product;
import com.agriculture.mapper.ProductMapper;
import com.agriculture.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ConsumerServiceImpl implements ConsumerService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public Response<?> getMarketProducts(String keyword, String category, int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        
        List<Product> products = productMapper.getMarketProducts(keyword, category, offset, pageSize);
        int total = productMapper.countMarketProducts(keyword, category);
        
        Map<String, Object> data = new HashMap<>();
        data.put("items", products);
        data.put("total", total);
        
        return Response.success("获取成功", data);
    }
}
